package org.semanticflash.rdf.values
{



	public class RDFTypedLiteral extends RDFLiteral
	{
		
		private var _datatype:IRI;

		public function get datatype():IRI
		{
			return _datatype;
		}

		public function RDFTypedLiteral( lexicalValue:String, datatype:IRI )
		{
			super( lexicalValue );
			_datatype = datatype;
		}
		

		
		
		// cache for performance
		private var _nt:String;
		
		override public function get nt():String
		{
			if ( !_nt )
				_nt = super.nt + '^^' + this.datatype.nt;
			return _nt;
		}







		/**
		 * 
		 * <b>Factory</b>
		 * 
		 * 
		 * @param lexicalValue
		 * @param datatype
		 * @return 
		 * 
		 */
		public static function instance( lexicalValue:String, datatype:IRI ):RDFTypedLiteral
		{
			
			var key:String, cachedTerm:RDFValue;			
			
			// why are cache keys so weird??
			// * we put lexicalValues in the end to avoid having to quote ( there is a chance that the lexical value matches our same structure )
			key = "t_" + hash( datatype.stringForm + " " + lexicalValue );
			
			cachedTerm = getCachedValue( key );
			
			if ( cachedTerm )
			{
				return cachedTerm as RDFTypedLiteral;
			}
				
			return cacheValue( key, new RDFTypedLiteral( lexicalValue, datatype ) ) as RDFTypedLiteral;				
		}









		
	}
	

}